package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements Ioperation{
    int flg = -1;
    @Override
    public void work(BookList bookList) {
        System.out.println("删除书籍");


        int current = bookList.getNum();

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要删去的书名");
        String name = scanner.nextLine();

        for (int i = 0; i < current; i++) {
            Book book = bookList.getBooks(i);

            //找书
            if (book.getName().equals(name)){
                     flg = i;
            }
        }
       if(flg == -1){
           System.out.println("没找到要删除的书");
       }
       else {
           for (int j= flg; j < current-1; j++) {
               Book book = bookList.getBooks(j+1);

               bookList.setBooks(j,book);
           }
           System.out.println("删除成功");
           bookList.setNum(current-1);
       }

    }

    }

